import numpy as np
# 假设 Matrix_similarity、Test 和 NoExist 已经定义
Matrix_similarity = np.array([[0.1, 0.2, 0.3],
                              [0.4, 0.5, 0.6],
                              [0.7, 0.8, 0.9]])

Test = np.array([[0, 1, 0],
                 [1, 0, 0],
                 [0, 0, 0]])

NoExist = np.array([[1, 0, 1],
                    [0, 1, 1],
                    [1, 1, 1]])

TestPre = Matrix_similarity * Test
NoExistPre = Matrix_similarity * NoExist

TestIndex = np.argwhere(Test == 1)
Test_Data = np.array([TestPre[x[0], x[1]] for index, x in enumerate(TestIndex)]).T
NoExistIndex = np.argwhere(NoExist == 1)
NoExist_Data = np.array([NoExistPre[x[0], x[1]] for index, x in enumerate(NoExistIndex)]).T

print("TestIndex:")
print(TestIndex)
print("Test_Data:")
print(Test_Data)
print("NoExistIndex:")
print(NoExistIndex)
print("NoExist_Data:")
print(NoExist_Data)